/** @format */

const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  minimize: true,
  minimizer: [
    '...',
    new CssMinimizerPlugin(),
    new TerserPlugin({
      terserOptions: {
        parallel: true, // 开启多线程压缩
        // https://github.com/terser/terser#minify-options
        compress: {
          warnings: false, // 删除无用代码时是否给出警告
          drop_debugger: true, // 删除所有的debugger
          // drop_console: true, // 删除所有的console.*
          pure_funcs: [''],
          // pure_funcs: ['console.log'], // 删除所有的console.log
        },
      },
    }),
	],
	usedExports:true,
	splitChunks: {
		minSize: 30000,
		maxInitialRequests: Infinity,
    chunks: 'all', // 默认只作用于异步模块，为`all`时对所有模块生效,`initial`对同步模块有效
    cacheGroups: {
      common: {
        name: 'common',
        test: /[\\/]node_modules[\\/](react|react-dom|react-router-dom)[\\/]/,
        priority: 10,
        chunks: 'all',
      },
      antdBase: {
        name: 'antdBase',
        test: /[\\/]node_modules[\\/](antd|@ant-design)[\\/]/,
        priority: 9,
        chunks: 'all',
      },
      vendors: {
        name: 'vendors',
        test: /[\\/]node_modules[\\/]/,
        chunks: 'all',
				priority: -10,
				minChunks: 2,
      },
      // 低频第三方组件
			lowFrequency: {
				name: 'lowFrequency',
        test: /[\\/]node_modules[\\/](echarts|echarts-for-react)/,
        minChunks: 1,
        priority: 7,
      },
		},
	},
	runtimeChunk: {
		name: (entrypoint) => `runtime~${entrypoint.name}`,
	},
};
